from tools_algorithm import *


class Solution:
    def takeCharacters(self, s: str, k: int) -> int:
        cnt = Counter(s)

        def c(cnt):
            return cnt["a"] < k or cnt["b"] < k or cnt["c"] < k

        if c(cnt):
            return -1

        def f(n):
            n = len(s) - n
            ctcp = cnt.copy()
            for i in range(len(s)):
                ctcp[s[i]] -= 1
                if i >= n:
                    ctcp[s[i - n]] += 1
                if i >= n - 1 and not c(ctcp):
                    return True
            return False

        return bisect_left(range(len(s) + 1), True, key=f)


s = Solution()
print(s.takeCharacters("a", 0))
# print(s.takeCharacters("aabaaaacaabc", 2))
